/* **************************************************
 * User Group Manager
 *      author:     Baskin Tapkan - baskint@hotmail.com
 *          written for Code Plex
 *              April - 2008
 *                  http://tapkan.com
 * ****************************************************
 */

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace UserGroupManager
{
    public partial class NewGroup : Form
    {
        string computerName = string.Empty;

        public NewGroup(string systemName)
        {
            computerName = systemName;

            InitializeComponent();
            this.Text = string.Format("New group for {0}", computerName);
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void NewGroup_Load(object sender, EventArgs e)
        {

        }

        private void txtGroupName_TextChanged(object sender, EventArgs e)
        {
            btnCreate.Enabled = true;
        }

        private void btnCreate_Click(object sender, EventArgs e)
        {
            // check whether the current group name exists in the underlying system
            GroupMgr gm = new GroupMgr();
            gm.ComputerName = computerName;

            if (!gm.CheckGroup(txtGroupName.Text))
            {

                bool res = gm.CreateNewGroup(txtGroupName.Text, txtDescription.Text);
                if (res)
                    staGrpMgr.Items[0].Text = "Group created successfully";
            }
            else
                staGrpMgr.Items[0].Text = "Groups exists on target system";
        }
    }
}